<?
  $id        = 0;
  $conference_id  = null;
  $venue_id     = null;
  $schedule     = date('Y-m-d H:i');
  $first_team_id   = null;
  $second_team_id = null;
  $notes       = null;
  $published     = true;
  
  if(isset($this->schedule)){
    $id        = $this->schedule->id;
    $conference_id  = $this->schedule->conference_id;
    $venue_id     = $this->schedule->venue_id;
    $schedule     = strftime('%Y-%m-%d %H:%M', strtotime($this->schedule->schedule));
    $first_team_id   = $this->schedule->first_team_id;
    $second_team_id = $this->schedule->second_team_id;
    $notes       = $this->schedule->notes;
    $published     = $this->schedule->published;  
  }
  
  $teams = array();
  if(isset($this->teams))
    $teams = $this->teams;
?>
<form action="index.php" method="post" name="adminForm" id="adminForm">
<script type="text/javascript">
jQuery(document).ready(
  function(){
    jQuery.validator.addMethod(
      "not_same", 
      function(value, element, params){
        var first  = jQuery(params[0]).val();
        var second = jQuery(params[1]).val();
        return this.optional(element) || first!=second;
      },
      "Teams should not be same");
      
    <? if(!isset($this->schedule)): ?>
      jQuery('#conference_id').change();
    <? endif; ?>
    jQuery("#adminForm").validate({
      rules:  {
        schedule:{
          required: true
          //date: true
        },
        second_team_id:{
          not_same: ['#first_team_id', '#second_team_id']
        }
      }
    });
  }
);
</script>
  <fieldset class="adminform">
    <legend>Details</legend>
            <table class="admintable">
                <tr>
                    <td class="key">Conference</td>
          <td>
            <?
              $options  = array();
              for($i=0; $i< count($this->conferences);$i++){
                $conference = $this->conferences[$i];
                array_push($options, JHTML::_('select.option', $conference->id, strtoupper($conference->name)));
              }
              $conference_link = "onchange=\"ajx_request('". JRequest::getVar('c', 'position') ."', 'ajx_select_conferences', 'conference_id='+this.value, 'div_conference');\"";
            ?>
            <?= JHTML::_('select.genericlist', $options, 'conference_id', $conference_link, 'value', 'text', $conference_id);?>
          </td>
        </tr>
        <tr>
                    <td class="key">Teams</td>
          <td>
            <div id="div_conference">
              <?= JHTML::_('select.genericlist', $teams, 'first_team_id', 'size=10', 'id', 'name', $first_team_id);?>
              &nbsp;VS.&nbsp;
              <?= JHTML::_('select.genericlist', $teams, 'second_team_id', 'size=10', 'id', 'name', $second_team_id);?>
            </div>
          </td>
        </tr>
        <tr>
                    <td class="key">Schedule</td>
          <td>
            <?= JHTML::calendar($schedule, "schedule", "schedule", "%Y-%m-%d %H:%M",array('size' => 40)) ?>
          </td>
        </tr>
                <tr>
                    <td class="key">Venue</td>
          <td>
            <?= JHTML::_('select.genericlist', $this->venues, 'venue_id', 'size=10', 'id', 'name', $venue_id);?>
          </td>
        </tr>
        <tr>
                    <td class="key">Notes</td>
          <td>
            <?= $this->editor->display( 'notes', $notes, '100%', '150', '40', '5' ) ?>
          </td>
        </tr>
        <tr>
          <td class="key">Published</td>
          <td>
            <?= JHTML::_('select.booleanlist', 'published', 'class="inputbox"', $published); ?>
          </td>
        </tr>
             </table>
       </fieldset>
       <input type="hidden" name="option" value="<?= JRequest::getVar( 'option' );?>"/>
     <input type="hidden" name="c" value="<?= JRequest::getVar('c', 'division'); ?>" />
       <input type="hidden" name="id" value="<?= $id ?>"/>      
       <input type="hidden" name="task" value=""/>
</form>